#@layout()

#define main()
<style type="text/css">
	.my-skin .layui-layer-btn a{
		background-color:#337ab7;
		border:1px solid #2e6da4;
	}
</style>
<div class="jfa-header-box" id="jfa-header-box">
	<div class="jfa-crumbs" id="jfa-crumbs">
		扫描枪信息
	</div>
	#include("/_view/common/_header_right.html")
</div>
<div class="jfa-content-box" id="jfa-content-box">
	<div class="jfa-content" id="jfa-content">
		

		<div id="toolbar" class="btn-group">
			<a class="btn btn-primary btn-sm margin-right-10" href="#" onclick="searchScanner()">
				<i class="fa fa-refresh"></i>
				刷新
			</a>
	        <a class="btn btn-primary btn-sm margin-right-10" href="#(ctx)/admin/scanner/add">
				<i class="fa fa-plus"></i>
				添加扫描枪
			</a>
			<a class="btn btn-primary btn-sm" href="#" onclick="showEmployeeNumber()">
                <i class="fa fa-plus"></i>
                员工号二维码
			</a>
			
	    </div>
		<table id="scanner">
			
		</table>
	</div>
</div>
<script type="text/javascript">
 	var datagridHeight=$("#jfa-content").height();
 	$('#scanner').bootstrapTable({
        url: '#(ctx)/admin/scanner/list',         
        method: 'get',
        toolbar: '#toolbar',
        striped: true,
        cache: false,
        pagination: true,
        sortable: false,                    
        sortOrder: "asc",  
        queryParams: function (params) {
	            var data = { 
	                    pageSize: params.limit,
	                    offset: params.offset
	            };
	            return data;
        },
        sidePagination: "server",
        pageNumber:1,
        toolbarAlign:"right",
        pageSize:210,         
        pageList: [210, 420,100],
        search: false,
        strictSearch: true,
        showColumns: false,
        showRefresh: false,             
        minimumCountColumns: 2,
        clickToSelect: true,               
       	height: datagridHeight,
        uniqueId: "id",
        showToggle:false,
        cardView: false,
        detailView: false,
        columns: [
            {
                field: 'remark',  title: '名称'
            }, {
                field: 'ip_address',  title: 'IP地址'
            }, {
                field: 'scanner_type',  title: '类型',formatter:typeFormatter
            }, {
            	field: 'employee_no',  title: '操作工编号'
            },{
            	field: 'userName',  title: '操作工'
            },{
            	field: 'update_time',  title: '更新时间'
            },{
            	title: '禁用',formatter:statusFormatter
            },{
            	title: '操作',formatter:operaterFormatter
            }
        ],
        onLoadSuccess:function(){
        	initMagicInput(prepareAction);
        }
});


function typeFormatter(value, row, index){
	if(value){
		if(value==1){
			return "上线手动扫描枪";
		}else if(value==2){
			return "上线自动扫描枪";
		}else if(value==3){
			return "下线自动扫描枪";
		}else if(value==4){
			return "下线手动扫描枪";
		}else{
			return "-";
		}
	}else{
		return "-";
	}
}
 	
function statusFormatter(value, row, index){
	var result="<input data-id='"+row.id+"'";
	if (row.scanner_status==-1){
		result+=" checked ";
	}
	 
	result+="type='checkbox' class='mgc-switch mgc-tiny'>";	  

	return result;
}

function prepareAction($this, state) {
	return {
		url: state ? "#(ctx)/admin/scanner/lock" : "#(ctx)/admin/scanner/unlock",
		data : {
			id: $this.attr("data-id")
		}
	}
}

function operaterFormatter(value, row, index){
	return "<a href='#(ctx)/admin/scanner/edit?id="+row.id+"'>"+
	"<i class='fa fa-pencil' title='修改'></i>"+
	" </a> &nbsp"+
	 "<a href='#(ctx)/admin/scanner/bindAccount?id="+row.id+"'>"+
	"<i class='fa fa-user' title='绑定员工'></i>"+
	" </a> &nbsp"+
	"<a  href='#' onclick='deleteScanner(\""+row.id+"\")'>"+
	"	<i class='fa fa-trash' title='删除'></i>"+
	"</a>"
}

function deleteScanner(id){
	layer.confirm("确认删除该记录？", {
		icon: 0
		, title:'' 
		, shade: 0.4
		, offset: "139px"
	}, function(index) { 
		$.ajax({
			url:"#(ctx)/admin/scanner/delete",
			data:{"id":id},
			dataType:"json",
			success:function(ret){
				$('#scanner').bootstrapTable("refresh",{silent: true});
			    layer.msg(ret.msg);
			    layer.close(index);   
			},
			error:function(){
				layer.close(index);   
			}
		});                           
		                       
	});
}

function searchScanner(){
	$('#scanner').bootstrapTable("refresh",{silent: true});
}

function showEmployeeNumber() {
    layer.open({
        type: 2,
        area: ['400px', '400px'],
        fixed: false, //不固定
        maxmin: false,
        title:'员工号',
        content: '#(ctx)/admin/scanner/showEmployeeNumberQcode',
		skin:'my-skin',
		btn:['打印'],
		yes:function (index,layero) {
			$(layero).find('iframe')[0].contentWindow.print();
        }

    });
}

</script>
#end
